package com.treetao.union.mall.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.treetao.union.db.service.MallPCataService;
import com.treetao.union.mall.api.base.BaseCURDController;
import com.treetao.union.mall.api.vo.req.ReqParam;

/**
 * 分类
 * 
 * @author devm
 *
 */
@RestController
@RequestMapping("/mall/cata")
public class MallCataController extends BaseCURDController {
	@Autowired
	private MallPCataService mallPCataService;

	@Override
	protected IService<?> getCommonService() {
		return mallPCataService;
	}
	@Override
	protected boolean setCommonDataAuth() {
		return false;
	}

	//分类
	@Override
	protected void commonListWhere(QueryWrapper<?> q,ReqParam param) {
		String type = param.getValue("type");
		if("second".equals(type)) {//二级
			Long cataid = param.getLong("cataid");
			if(cataid!=null) {
				q.eq("refcataid", cataid);
			}
		} else {//一级
			q.isNull("refcataid");
		}
		q.orderByAsc("orderby").select("id","name","icon");
	}
}
